package com.manage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.clms.common.R;
import com.manage.mapper.ClientMapper;
import com.manage.pojo.entity.TbClient;
import com.manage.pojo.vo.ClientVo;
import com.manage.service.ClientService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @program: clms-third
 * @description: 会员管理的实现类
 * @author: 林子洁
 * @create: 2021-07-22 15:44
 **/
@Service
public class ClientServiceImpl implements ClientService {
    @Resource
    private ClientMapper clientMapper;
    @Override
    public R initClient(Integer currtenPage, Integer pageSize, ClientVo clientVo) {
        Page<TbClient> page=new Page<>(currtenPage,pageSize);
        //模糊查询 账户和昵称
        QueryWrapper<TbClient> wrapper=new QueryWrapper<>();
        if(StringUtils.isNotEmpty(clientVo.getUsername())){
            wrapper.like("username", clientVo.getUsername());
        }
        if(StringUtils.isNotEmpty(clientVo.getName())){
            wrapper.like("name", clientVo.getName());
        }
        //分页

        Page<TbClient> clientPage = clientMapper.selectPage(page, wrapper);
        return R.ok().put("records",clientPage.getRecords()).put("total",clientPage.getTotal());
    }

    @Override
    public R insertClient(TbClient client) {
         clientMapper.insert(client);
        return R.ok().message("插入成功");
    }

    @Override
    public R updateStatus(Integer id, Integer status) {
        clientMapper.updateStatus(id,status);
        return R.ok().message("修改成功");
    }
}
